package cn.com.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import cn.com.entity.KeShi;

public class KeShiDao {
	private  static SessionFactory sessionFactory;

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	Session session;
	Transaction transaction;
	public List<KeShi> chakankeshi(){
		session=sessionFactory.openSession();
		String hql="from KeShi";
		Query query=session.createQuery(hql);
		List<KeShi> cklist=query.list();
		return cklist;
	}
	public boolean insertkeshi(int keshiid,String keshiming){
		boolean b=false;
		session=sessionFactory.openSession();
		KeShi keshi=new KeShi();
		keshi.setKeshiid(keshiid);
		keshi.setKeshiming(keshiming);
		transaction=session.beginTransaction();
		if(keshi!=null){
			session.save(keshi);
			transaction.commit();
			session.close();
			b=true;
		}
		return b;
	}
	public boolean updatekeshi(int keshiid,String keshiming){
		boolean b=false;
		session=sessionFactory.openSession();
		KeShi keshi=getkeshi(keshiid);
		keshi.setKeshiming(keshiming);
		transaction=session.beginTransaction();
		if(keshi!=null){
			session.update(keshi);
			transaction.commit();
			session.close();
			b=true;
		}return b;
	}
	public KeShi getkeshi(int keshiid){
		session=sessionFactory.openSession();
		KeShi keshi=(KeShi)session.get(KeShi.class, keshiid);
		return keshi;
	}
	public boolean deletekeshi(int keshiid){
		boolean b=false;
		session=sessionFactory.openSession();
		KeShi keshi=getkeshi(keshiid);
		transaction=session.beginTransaction();
		if(keshi!=null){
			session.delete(keshi);
			transaction.commit();
			session.close();
			b=true;
		}
		return b;
	}
}
